#!/usr/bin/python


text = r'''
Welcome to ReText! S1
==================

ReText is a simple but powerful editor for Markdown and reStructuredText markup
languages. ReText is written in Python language and works on Linux and other


.notes: ReText is written in Python


---

Hola mundo
=========

---

asdf
=====


render.py
---------

First code block:

    ::python
    import jinja2
    import markdown

    with open('presentation.html', 'w') as outfile:
        slides_src = markdown.markdown(open('slides.md').read()).split('<hr />\n')

        slides = []

        for slide_src in slides_src:
            header, content = slide_src.split('\n', 1)
            slides.append({'header': header, 'content': content})

        template = jinja2.Template(open('base.html').read())

        outfile.write(template.render({'slides': slides}))


----




hola mundo S2 
=========


Footnotes[^1] have a label[^label] and a definition[^!DEF].

[^1]: This is a footnote
[^label]: A footnote on "label"
[^!DEF]: The definition of a footnote.

- Put your markdown content in a file called `slides.md`
- Run `python render.py`
- Enjoy your newly generated `presentation.html`    
	

---

A slide in a subdirectory S3 
=========================

It also works.

An image:

![monkey](monkey.jpg)

---

Slide #2 S4
========

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean magna tellus,
fermentum nec venenatis nec, dapibus id metus. Phasellus nulla massa, consequat
nec tempor et, elementum viverra est. Duis sed nisl in eros adipiscing tempor

Section #1
----------

Integer in dignissim ipsum. Integer pretium nulla at elit facilisis eu feugiat
velit consectetur.

Section #2
----------

[TOC]


Donec risus tortor, dictum sollicitudin ornare eu, egestas at purus. Cras
consequat lacus vitae lectus faucibus et molestie nisl gravida. Donec tempor,
tortor in varius vestibulum, mi odio laoreet magna, in hendrerit nibh neque eu
eros.

'''


import markdown
import re
#~ md = markdown.Markdown(extensions=['footnotes'],output_format='html5')
#~ md = markdown.Markdown(output_format='xhtml5',extensions=['extra','toc','meta','html_tidy','codehilite'])
md = markdown.Markdown(output_format='html5',extensions=['extra','meta','html_tidy','codehilite'])

#~ slides = re.split('\n\n-{3,8}\n',text)
#~ 
#~ slide_i='''<div class="slide-wrapper"><div class="slide"><div class="inner">'''
		#~ 
#~ slide_f='''</div></div></div>'''
#~ toc= '''<div id="toc" class="sidebar hidden"><h2>Tabla de Contenidos</h2><table><caption>Tabla de Contenidos</caption>'''      
      #~ 
  
def markslide(slides):
	
	slides = re.split('\n\n-{3,8}\n',text)

	slide_i='''<div class="slide-wrapper"><div class="slide"><div class="inner">'''
			
	slide_f='''</div></div></div>'''
	toc= '''<div id="toc" class="sidebar hidden"><h2>Tabla de Contenidos</h2><table><caption>Tabla de Contenidos</caption>'''      
		 
	texto_i='''
<!DOCTYPE html>
<!--
Copyright 2010 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Original slides: Marcin Wichary (mwichary@google.com)
Modifications: Ernest Delgado (ernestd@google.com)
Alex Russell (slightlyoff@chromium.org)

landslide modifications: Adam Zapletal (adamzap@gmail.com)
   Nicolas Perriault (nperriault@gmail.com)
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>Landslide</title>
<!-- Styles -->

<link rel="stylesheet" media="print" href="file:///usr/lib/python2.7/site-packages/landslide-1.0.1-py2.7.egg/landslide/themes/default/css/print.css">
<link rel="stylesheet" media="screen, projection" href="file:///usr/lib/python2.7/site-packages/landslide-1.0.1-py2.7.egg/landslide/themes/default/css/screen.css">


<!-- /Styles -->
<!-- Javascripts -->

<script type="text/javascript" src="file:///usr/lib/python2.7/site-packages/landslide-1.0.1-py2.7.egg/landslide/themes/default/js/slides.js"></script>


<!-- /Javascripts -->
</head>
<body>
<div id="blank">
</div>
<div class="presentation">
<div id="current_presenter_notes">
<div id="presenter_note">
</div>
</div>
<div class="slides">
	'''

	texto_f= '''
<div id="help" class="sidebar hidden">
<h2>Help</h2>
<table>
<caption>Help</caption>
<tr>
<th>Table of Contents</th>
<td>t</td>
</tr>
<tr>
<th>Exposé</th>
<td>ESC</td>
</tr>
<tr>
<th>Full screen slides</th>
<td>e</td>
</tr>
<tr>
<th>Presenter View</th>
<td>p</td>
</tr>
<tr>
<th>Source Files</th>
<td>s</td>
</tr>
<tr>
<th>Slide Numbers</th>
<td>n</td>
</tr>
<tr>
<th>Toggle screen blanking</th>
<td>b</td>
</tr>
<tr>
<th>Show/hide slide context</th>
<td>c</td>
</tr>
<tr>
<th>Notes</th>
<td>2</td>
</tr>
<tr>
<th>Help</th>
<td>h</td>
</tr>
</table>
</div>
<script>main()</script>
</body>
</html>
	'''

	n_s=0
	texto = texto_i
	for slide in slides:
		n_s +=1
		md.reset()
		te = md.convert(slide)
		te=re.sub(r'<p>\.notes:\s*(.*?)</p>',r'<p class="notes">\1</p>', te)
		#~ texto = texto + slide_i + te + slide_f
		find = re.search(r'(<h(\d+?).*?>(.+?)</h\d>)\s?(.+)?',te,re.DOTALL | re.UNICODE)
		if not find:
			header = title = ''
			level  = None
			content = te.strip()
		else:
			header = find.group(1)
			level = int(find.group(2))
			title = find.group(3)
			content = find.group(4).strip() if find.group(4) else find.group(4)
		header = r"<header>" + header +r"</header>"
		if content:
			content = r"<section>" + content + r"</section>"
			page_num = '<footer><aside class="page_number">'+str(n_s) + '</aside></footer>'
			  
			  
		else:
			content = page_num= ''
			
		texto = texto + slide_i + header + content + page_num + slide_f
		
		if level:
			toc = toc + '<tr id="toc-row-' + str(n_s) + '"><th><a href="#slide'+ str(n_s) + '">' + title + '</a></th><td><a href="#slide' + str(n_s) + '">'+str(n_s)+ '</a></td></tr>'
						 
	texto = texto + '</div></div>' +  toc + '</table></div>' + texto_f
	return(texto)

print(markslide(text))
	
	

